﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace Sinacor.Infra.UI.Controls.SmartClient
{
    public class WindowContentSizeConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double size;
            if (!double.TryParse(System.Convert.ToString(value), out size))
                throw new ArgumentException("The value must be double", "value");

            double margin;
            if (!double.TryParse(System.Convert.ToString(parameter), out margin))
                throw new ArgumentException("The parameter must be double", "parameter");

            if (!double.IsNaN(size) &&
                (size - margin) >= 0)
            {
                value = size - margin;
            }

            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
